<style type="text/css">
<!--
.style1 {color: #FF0000}
-->
</style>
<?php
	require ("../header.php");
	include ("../config/conn.php");
	
	if (isset($_POST['stud_name'])) {
		$stud_name=$_POST['stud_name'];
	}
	else {
		echo "<br><br><br><br><br><br><b><center>Registration Error.  Please Fill all the fields before submit.<br></center></b>";
		echo "<META http-equiv=\"refresh\" content=\"5;URL=../stud_reg.php\">";
	}
	if (isset($_POST['stud_password'])) {
	$stud_password=$_POST['stud_password'];
	}
	else {
		echo "<br><br><br><br><br><br><b><center>Registration Error.  Please Fill all the fields before submit.<br></center></b>";
		echo "<META http-equiv=\"refresh\" content=\"5;URL=../stud_reg.php\">";
	}
	if (isset($_POST['stud_no'])) {
	$stud_no=$_POST['stud_no'];
	}
	else {
		echo "<br><br><br><br><br><br><b><center>Registration Error.  Please Fill all the fields before submit.<br></center></b>";
		echo "<META http-equiv=\"refresh\" content=\"5;URL=../stud_reg.php\">";
	}
	if (isset($_POST['stud_ic'])) {
	$stud_ic=$_POST['stud_ic'];
	}
	else {
		echo "<br><br><br><br><br><br><b><center>Registration Error.  Please Fill all the fields before submit.<br></center></b>";
		echo "<META http-equiv=\"refresh\" content=\"5;URL=../stud_reg.php\">";
	}
	if (isset($_POST['stud_course'])) {
	$stud_course=$_POST['stud_course'];
	}
	else {
		echo "<br><br><br><br><br><br><b><center>Registration Error.  Please Fill all the fields before submit.<br></center></b>";
		echo "<META http-equiv=\"refresh\" content=\"5;URL=../stud_reg.php\">";
	}
	if (isset($_POST['stud_sem'])) {
	$stud_sem=$_POST['stud_sem'];
	}
	else {
		echo "<br><br><br><br><br><br><b><center>Registration Error.  Please Fill all the fields before submit.<br></center></b>";
		echo "<META http-equiv=\"refresh\" content=\"5;URL=../stud_reg.php\">";
	}
	if (isset($_POST['stud_department'])) {
	$stud_department=$_POST['stud_department'];
	}
	else {
		echo "<br><br><br><br><br><br><b><center>Registration Error.  Please Fill all the fields before submit.<br></center></b>";
		echo "<META http-equiv=\"refresh\" content=\"5;URL=../stud_reg.php\">";
	}
	if (isset($_POST['stud_class'])) {
	$stud_class=$_POST['stud_class'];
	}
	else {
		echo "<br><br><br><br><br><br><b><center>Registration Error.  Please Fill all the fields before submit.<br></center></b>";
		echo "<META http-equiv=\"refresh\" content=\"5;URL=../stud_reg.php\">";
	}
	
	
	if ($stud_name!=NULL && $stud_password!=NULL && $stud_no!=NULL 
			&& $stud_ic!=NULL && $stud_course!=NULL && $stud_sem!=NULL && $stud_department!=NULL) {
		$sql_check_uname="SELECT stud_no FROM student WHERE stud_no='$stud_no'";
		$check_uname=mysql_query($sql_check_uname);
		$uname_stat=mysql_num_rows($check_uname);
		
		if ($uname_stat==0) {
			$date=date('Y-m-d');
			$sql_stud_reg="INSERT INTO student (stud_name,stud_password,stud_no,stud_ic,stud_course,stud_sem,stud_deparment,last_update,class)
							VALUES ('$stud_name',MD5('$stud_password')
							,'$stud_no','$stud_ic','$stud_course','$stud_sem','$stud_department','$date','$stud_class')";
			$sql_check_reg="SELECT stud_no FROM student WHERE stud_no='$stud_no'";
					
			$result=mysql_query($sql_stud_reg) or die ("mati disni");
			$result2=mysql_query($sql_check_reg);
			$check=mysql_num_rows($result2);
		}
		else { $check = 4;  }
		}
	else { $check = 2; }
	
	
	if ($check==1)
	{
	?>
	<div align="center">
	  <p>&nbsp;</p>
	  <p>&nbsp;</p>
	  <p>&nbsp;</p>
	  <table width="700" border="0" bordercolor="#999999" bgcolor="#999999">
   		 <tr>
      	<td bgcolor="#000000"><br /><font color="red" size="2px"><center>THANK YOU FOR REGISTERING.  YOUR REGISTRATION HAS BEEN SUCCESSFUL.</center></font><br /></td>
    		</tr>
  		</table>
	  <p>&nbsp;</p>
	  <p>&nbsp;</p>
	  <p>&nbsp;</p>
	  <p>&nbsp;</p>
	</div>
	<?php }
	elseif ($check==2) { ?>
	  <div align="center">
	  <p>&nbsp;</p>
	  <p>&nbsp;</p>
	  <p>&nbsp;</p>
	  <table width="700" border="0" bordercolor="#999999" bgcolor="#999999">
    	<tr>
      <td bgcolor="#000000"><br /><font color="red" size="2px"><center>PLEASE FILL IN ALL FIELDS BEFORE SUBMITTING</center></font><br /></td>
   	 	</tr>
  		</table>
	  <p>&nbsp;</p>
	  <p>&nbsp;</p>
	  <p>&nbsp;</p>
	  <p>&nbsp;</p>
	  </div> 
	<?php }
	else 
	{  ?>
		<div align="center">
	  <p>&nbsp;</p>
	  <p>&nbsp;</p>
	  <p>&nbsp;</p>
	  <table width="700" border="0" bordercolor="#999999" bgcolor="#999999">
    	<tr>
      <td bgcolor="#000000"><br /><font color="red" size="2px"><center>YOUR REGISTRATION FAILED.  USERNAME ALREADY TAKEN. PLEASE CHOOSE ANOTHER USERNAME.</center>
	  </font><br /></td>
    	</tr>
  	</table>
	  <p>&nbsp;</p>
	  <p>&nbsp;</p>
	  <p>&nbsp;</p>
	  <p>&nbsp;</p>
	</div>
	<?php 
	echo "<META http-equiv=\"refresh\" content=\"5;URL=../stud_reg.php?name=".$stud_name."&&no=".$stud_no."&&ic=".$stud_ic."&&course=".$stud_course."
	&&department=".$stud_department."&&sem=".$stud_sem."\">"; 
	} 
	
	require ("../footer.php");
?>
